
ac.buff('不朽者头盔'){
    count = 0,
    on_add = function(self)
		local unit = self.owner
        self.count = 0
        self:gc(ac.loop(1000,function()
            local num = unit:get('力量') * 2
            unit:add('生命上限',num - self.count)
            self.count = num
        end))
    end,
    
    on_remove = function(self)
		local unit = self.owner
        unit:add('生命上限',-self.count)
        self.count = 0
    end,
}


ac.buff('破坏神之剑'){
    count = 0,
    on_add = function(self)
		local unit = self.owner
        self.count = 0
        self:gc(ac.loop(1000,function()
            local num = unit:get('敏捷') * 0.5
            unit:add('物理固伤',num - self.count)
            self.count = num
        end))
    end,
    
    on_remove = function(self)
		local unit = self.owner
        unit:add('物理固伤',-self.count)
        self.count = 0
    end,
}



ac.buff('奥术魔典'){
    count = 0,
    on_add = function(self)
		local unit = self.owner
        self.count = 0
        self:gc(ac.loop(1000,function()
            local num = unit:get('智力') * 0.5
            unit:add('魔法固伤',num - self.count)
            self.count = num
        end))
    end,
    
    on_remove = function(self)
		local unit = self.owner
        unit:add('魔法固伤',-self.count)
        self.count = 0
    end,
}


ac.item('万象之符'){
    cool = 0.5,
    used_flag = false,
    item_type = 'permanent',
}
ac.buff('万象之符'){
    model1 = [[ZBJN_wwz.mdl]],
    on_add = function(self)
		local unit = self.owner
        self:gc(unit:event '单位-攻击触发被动'(function(_,_,target,data)
            self.open = self.open==true or math.random(100)<=20
        end))
        self:gc(unit:event '单位-攻击命中'(function(_,_,target,data)
            if self.item:is_cooling()==false and self.open then
                self.item:active_cd()
                self.open = nil
                local point1 = unit:get_point()
                local point2 = target:get_point()
                local damage = unit:get('攻击') * 2
                local angle = point1 / point2
                local lock = {}
                for a=0,2 do
                    local point = point2 - {angle,250*a}
                    ac.wait(a*100,function()
                        point:effect{
                            model = self.model1,
                            time = 1,
                        }
                        ac.wait(200,function()
                            unit:aoe_damage(point,250,damage,self,lock)
                        end)
                    end)
                end
            end
        end))
    end,
}


ac.buff('山丘之握'){
    on_add = function(self)
		local unit = self.owner
        self:gc(unit:add('杀敌力量',0.5))
    end,
}


ac.buff('幽影噬魂刃'){
    on_add = function(self)
		local unit = self.owner
        self:gc(unit:add('杀敌敏捷',0.5))
    end,
}

ac.buff('神灵法杖'){
    on_add = function(self)
		local unit = self.owner
        self:gc(unit:add('杀敌智力',0.5))
    end,
}


ac.buff('坠日之箭'){
    count = 0,
    on_add = function(self)
		local unit = self.owner
        self.count = 0
        self:gc(ac.loop(1000,function()
            local num = math.max(unit:get('多重伤害') - 100,0) * 0.5
            unit:add('伤害增幅',num - self.count)
            self.count = num
        end))
    end,
    
    on_remove = function(self)
		local unit = self.owner
        unit:add('伤害增幅',-self.count)
        self.count = 0
    end,
}


ac.buff('弹射核心'){
    count = 0,
    on_add = function(self)
		local unit = self.owner
        self.count = 0
        self:gc(ac.loop(1000,function()
            local num = math.max(unit:get('弹射伤害') - 100,0) * 0.5
            unit:add('攻击加成',num - self.count)
            self.count = num
        end))
    end,
    
    on_remove = function(self)
		local unit = self.owner
        unit:add('攻击速度',-self.count)
        self.count = 0
    end,
}



ac.item('回溯之书'){
    used_flag = false,
    item_type = 'permanent',
    cool = 4,
    cooling_flag = false,
}
ac.buff('回溯之书'){
    on_add = function(self)
		local unit = self.owner
        self:gc(unit:event '单位-攻击触发被动'(function(_,_,target,skill)
            if self.item:is_cooling()==false then
                self.item:active_cd()
                skill:set_cd(0)
            end
        end))
    end,
}



ac.buff('力量宝珠'){
    on_add = function(self)
		local unit = self.owner
        local count = unit:get_data('力量宝珠-次数') or 0
        self.item:set_count(count)
        self:gc(unit:event '单位-英雄升级'(function()
            local count = unit:get_data('力量宝珠-次数') or 0
            if count<15 then
                unit:add('力量加成',1)
                unit:set_data('力量宝珠-次数',count+1)
                self.item:set_count(count)
            end
        end))
    end,
}

ac.buff('敏捷宝珠'){
    on_add = function(self)
		local unit = self.owner
        local count = unit:get_data('敏捷宝珠-次数') or 0
        self.item:set_count(count)
        self:gc(unit:event '单位-英雄升级'(function()
            local count = unit:get_data('敏捷宝珠-次数') or 0
            if count<15 then
                unit:add('敏捷加成',1)
                unit:set_data('敏捷宝珠-次数',count+1)
                self.item:set_count(count)
            end
        end))
    end,
}

ac.buff('智力宝珠'){
    on_add = function(self)
		local unit = self.owner
        local count = unit:get_data('智力宝珠-次数') or 0
        self.item:set_count(count)
        self:gc(unit:event '单位-英雄升级'(function()
            local count = unit:get_data('智力宝珠-次数') or 0
            if count<15 then
                unit:add('智力加成',1)
                unit:set_data('智力宝珠-次数',count+1)
                self.item:set_count(count)
            end
        end))
    end,
}


ac.buff('审批巨矛'){
    on_add = function(self)
		local unit = self.owner
        self:gc(unit:event '单位-攻击命中'(function(_,_,target,data)
            local damage = unit:get('力量') * 0.3
            unit:create_damage(target,damage,self)
        end))
    end,
}

ac.buff('月光匕首'){
    on_add = function(self)
		local unit = self.owner
        self:gc(unit:event '单位-攻击命中'(function(_,_,target,data)
            local damage = unit:get('敏捷') * 0.3
            unit:create_damage(target,damage,self)
        end))
    end,
}

ac.buff('虚空魔杖'){
    on_add = function(self)
		local unit = self.owner
        self:gc(unit:event '单位-攻击命中'(function(_,_,target,data)
            local damage = unit:get('智力') * 0.3
            unit:create_damage(target,damage,self)
        end))
    end,
}

ac.item('再生圣杯'){
    cool = 60,
    used_flag = false,
    item_type = 'permanent',
}
ac.buff('再生圣杯'){
    on_add = function(self)
		local unit = self.owner
        self:gc(unit:event '单位-受到伤害'(function()
            if unit:get('当前生命百分比')<20 and self.item:is_cooling()==false then
                self.item:active_cd()
                unit:add_buff '再生圣杯-效果'{
                    time = 3,
                    on_add = function(buff)
                        self:gc(unit:add('百分比生命恢复',10))
                    end,
                }
            end
        end))
    end,
}

ac.buff('独角兽长弓'){
    on_add = function(self)
		local unit = self.owner
        self:gc(unit:add('攻击距离%',10))
    end,
}

ac.buff('女神的祝福'){
    on_add = function(self)
		local unit = self.owner
        self:gc(unit:add('每秒力量',2))
        self:gc(unit:add('每秒敏捷',2))
        self:gc(unit:add('每秒智力',2))
    end,
}


ac.buff('毁灭双刃'){
    on_add = function(self)
		local unit = self.owner
        self:gc(unit:event '单位-造成伤害前'(function(_,_,_,data)
            data:mul(30)
        end))
        self:gc(unit:event '单位-受到伤害前'(function(_,_,_,data)
            data:mul(50)
        end))
    end,
}

ac.buff('地精的矿稿'){
    on_absorb = function(self, unit)
        unit.owner:add('金币',20000)
    end,
}


ac.item('魔法神锤'){
    cool = 4,
    used_flag = false,
    item_type = 'permanent',
}
ac.buff('魔法神锤'){
    model1 = [[ZBJN_mfsc.mdl]],
    on_add = function(self)
		local unit = self.owner
        self:gc(unit:event '单位-攻击命中'(function(_,_,target,data)
            if self.item:is_cooling()==false and math.random(100)<=12 then
                self.item:active_cd()
                local point1 = unit:get_launch_point()
                local point2 = target:get_point()
                local angle = point2 / point1
                local damage = unit:get('生命恢复') * 2
                
                local num = 3
                local jd = {0,90,-90}
                for a=1,num do
                    local r = angle + jd[a]
                    local p = point1 - {r,250}
                    p.z = point1.z
                    ac.wait(a*200,function()
                        local effect = unit:create_shadow(p,p/point2,1)
                        effect:play_animation('spell 2')
                        ac.wait(200,function()
                            local mover = p:launch_missile(point2,self.model1,900,0.15,function()
                                unit:aoe_damage(point2,250,damage,self)
                            end)
                            mover.mover:set_scale(3)
                        end)
                    end)
                end
            end
        end))
    end,
}


ac.item('世界树枝'){
    count = 2000,
    used_flag = false,
}
ac.buff('世界树枝'){
    on_add = function(self)
		local unit = self.owner
        self:gc(unit:event '英雄-击杀单位'(function(trg)
            self.item:add_count(-1)
            if self.item:get_count()<=0 then
                unit:notify('单位-吞噬物品', unit, self.item)
            end
        end))
    end,
}

ac.item('狂战士意志'){
    cool = 30,
    used_flag = false,
    item_type = 'permanent',
}
ac.buff('狂战士意志'){
    on_add = function(self)
		local unit = self.owner
        self:gc(unit:event '单位-攻击命中'(function(trg)
            if self.item:is_cooling()==false then
                self.item:active_cd()
                unit:add_buff '狂战士意志-效果'{
                    time = 8,
                    art = self.art,
                    title = self.title,
                    tip = [[攻击/攻速/间隔提升]],
                    on_add = function(buff)
                        buff:gc(unit:add_effect('weapon left',[[Abilities\Spells\Orc\TrollBerserk\HeadhunterWEAPONSLeft.mdl]]))
                        buff:gc(unit:add_effect('weapon right',[[Abilities\Spells\Orc\TrollBerserk\HeadhunterWEAPONSRight.mdl]]))
                        buff:gc(unit:add('攻击加成',30))
                        buff:gc(unit:add('攻击速度',100))
                        buff:gc(unit:add('攻击间隔',-0.1))
                    end,
                }
            end
        end))
    end,
}

ac.buff('光明圣甲'){
    count = 0,
    on_add = function(self)
		local unit = self.owner
        self.count = 0
        self:gc(ac.loop(1000,function()
            local num = math.floor(unit:get('生命上限')/100) * 2
            unit:add('基础攻击',num - self.count)
            self.count = num
        end))
    end,
    
    on_remove = function(self)
		local unit = self.owner
        unit:add('基础攻击',-self.count)
        self.count = 0
    end,
}

ac.buff('后裔神持'){
    count = 0,
    on_add = function(self)
		local unit = self.owner
        self.count = 0
        self:gc(ac.loop(1000,function()
            local num = math.floor(unit:get('攻击距离')/150) * 1
            unit:add('伤害增幅',num - self.count)
            self.count = num
        end))
    end,
    
    on_remove = function(self)
		local unit = self.owner
        unit:add('伤害增幅',-self.count)
        self.count = 0
    end,
}



ac.buff('魔剑阿波菲斯'){
    count = 0,
    ['无法吞噬'] = true,
    on_add = function(self)
		local unit = self.owner
        self.num = 0
        local player = unit.owner
        local timer = ac.loop(1000,function()
            local list = player:get_data('装备吞噬列表') or {}
            local num = 1
            for _,it in ipairs(list) do
                if it.item_level>=6 then
                    num = num + 1
                end
            end
            unit:add('力量加成',(num - self.num) * 3)
            unit:add('敏捷加成',(num - self.num) * 3)
            unit:add('智力加成',(num - self.num) * 3)
            self.num = num
            self.item:set_count(num)
        end)
        timer:on_timer()
        self:gc(timer)
    end,
    
    on_remove = function(self)
		local unit = self.owner
		local unit = self.owner
        unit:add('力量加成',- self.num * 3)
        unit:add('敏捷加成',- self.num * 3)
        unit:add('智力加成',- self.num * 3)
    end,
}


ac.item('裁决者'){
    cool = 1,
    used_flag = false,
    item_type = 'permanent',
}
ac.buff('裁决者'){
    on_add = function(self)
		local unit = self.owner
        self:gc(unit:event '单位-触发暴击'(function(_,_,_,data)
            if self.item:is_cooling()==false and math.random(100)<=5 then
                data:mul(100)
                self.item:active_cd()
            end
        end))
    end,
}

ac.buff('神圣之泪'){
    on_absorb = function(self, unit)
        unit:notify('单位-添加物品属性',unit,self)
    end,
}

ac.buff('共生魂晶'){
    on_absorb = function(self, unit)
        ac.each_hero(function(hero)
            if unit~=hero then
                hero:notify('单位-添加物品属性',hero,self)
            end
        end)
    end,
}

